package com.clas.liu.myapplication.view.fragment.impl;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.clas.liu.myapplication.R;
import com.clas.liu.myapplication.presenter.impl.BaseFragmentPresenter;
import com.clas.liu.myapplication.view.activity.impl.ChatActivity;
import com.hyphenate.chat.EMConversation;
import com.hyphenate.easeui.EaseConstant;
import com.hyphenate.easeui.ui.EaseConversationListFragment;

/**
 * Created by liu on 2019/3/3.
 */

public class ChatFragment extends BaseFragment {

    private EaseConversationListFragment conversationFragment;
    private View root;
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        root = inflater.inflate(R.layout.fragment_chat_layout, container, false);
        findView();
        init();
        return root;

    }

    private void findView() {

    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        if (isVisibleToUser) {
            if (conversationFragment!=null)
                refresh();
        }
    }

    private void init() {
        conversationFragment = new EaseConversationListFragment();
        conversationFragment.setConversationListItemClickListener(new EaseConversationListFragment.EaseConversationListItemClickListener() {

            @Override
            public void onListItemClicked(EMConversation conversation) {
                //进入聊天页面
                startActivity(new Intent(getActivity(), ChatActivity.class).putExtra(EaseConstant.EXTRA_USER_ID, conversation.conversationId()));
            }
        });
        getChildFragmentManager().beginTransaction().add(R.id.chat_fragment_body,conversationFragment).commit();
    }

    @Override
    protected BaseFragmentPresenter getPresenter() {
        return null;
    }

    public void refresh() {
        conversationFragment.refresh();
    }
}
